package org.cuasloi.rabbitmq.topic;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TopicProduceController {

    // 注入SpringAMQP提供的模板
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("topicQueue/{routingKey}/{msg}")
    public void sendMsgToTopicExchange(@PathVariable("routingKey") String routingKey, @PathVariable("msg") String msg) {
        String exchangeName = "topic.exchange"; // 交换机名称
        rabbitTemplate.convertAndSend(exchangeName, routingKey, msg);
    }
}
